﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.Controls
{
    public partial class userlogin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["user_name"] != null)
                {
                    this.Panel1.Visible = false;
                    this.Panel2.Visible = true;
                    this.Label1.Text = "欢迎您：" + Session["user_name"].ToString();
                }

            }
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string name = this.TextBox1.Text.Trim();
                string pwd = this.TextBox2.Text.Trim();
                string checkcode = this.TextBox3.Text.Trim();
                if (Session["CheckCode"] != null)
                {
                    if (checkcode.ToUpper() == Session["CheckCode"].ToString())
                    {
                        lcmyjobs.BLL.user_basic bad = new BLL.user_basic();
                        string mname = "", time = "";
                        pwd = myPublic.GetMd5(pwd);
                        int id = bad.UserLogin(name, pwd, out mname, out time);
                        if (id != 0)
                        {
                            Session["user_id"] = id.ToString();
                            Session["user_name"] = mname;
                            //Response.Redirect("user_main.aspx");
                            this.Label1.Text = "欢迎您：" + mname;
                            this.Panel1.Visible = false;
                            this.Panel2.Visible = true;
                        }
                        else
                            Maticsoft.Common.MessageBox.Show(Page, "用户名或密码不对！");

                    }
                    else
                        Maticsoft.Common.MessageBox.Show(Page, "验证码不对！");
                }
                else
                    Maticsoft.Common.MessageBox.Show(Page, "验证码不对！");

            }
        }
    }
}